﻿#include "qualifydocu.h"
#include "ui_qualifydocu.h"
#include<QFileDialog>
#include<QFile>
#include<QTextCodec>
#include<QString>
#include<QCompleter>
#include<QMessageBox>
#include<QDebug>
#include"sqlconnect.h"
//#include "qserialport.h"
qualifyDocu::qualifyDocu(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::qualifyDocu)
{
    ui->setupUi(this);
    ui->nameEdit->setEnabled(false);
    ui->IDNumEdit->setEnabled(false);
    setLock();//初始化各控件
    ui->postTable->setSelectionBehavior ( QAbstractItemView::SelectRows); //设置选择行为，以行为单位
    ui->postTable->setSelectionMode ( QAbstractItemView::SingleSelection); //设置选择模式，选择单行
    ui->postTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->checkTable->setSelectionBehavior ( QAbstractItemView::SelectRows); //设置选择行为，以行为单位
    ui->checkTable->setSelectionMode ( QAbstractItemView::SingleSelection); //设置选择模式，选择单行
    ui->checkTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->rewardTable->setSelectionBehavior ( QAbstractItemView::SelectRows); //设置选择行为，以行为单位
    ui->rewardTable->setSelectionMode ( QAbstractItemView::SingleSelection); //设置选择模式，选择单行
    ui->rewardTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->punishTable->setSelectionBehavior ( QAbstractItemView::SelectRows); //设置选择行为，以行为单位
    ui->punishTable->setSelectionMode ( QAbstractItemView::SingleSelection); //设置选择模式，选择单行
    ui->punishTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->eduTable->setSelectionBehavior ( QAbstractItemView::SelectRows); //设置选择行为，以行为单位
    ui->eduTable->setSelectionMode ( QAbstractItemView::SingleSelection); //设置选择模式，选择单行
    ui->eduTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->workTable->setSelectionBehavior ( QAbstractItemView::SelectRows); //设置选择行为，以行为单位
    ui->workTable->setSelectionMode ( QAbstractItemView::SingleSelection); //设置选择模式，选择单行
    ui->workTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->familyTable->setSelectionBehavior ( QAbstractItemView::SelectRows); //设置选择行为，以行为单位
    ui->familyTable->setSelectionMode ( QAbstractItemView::SingleSelection); //设置选择模式，选择单行
    ui->familyTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    //实现各按钮功能
    //开始输入表头信息
    connect(ui->editButton,SIGNAL(clicked()),this,SLOT(click_edit()));
    //保存
    connect(ui->saveButton,SIGNAL(clicked(bool)),this,SLOT(click_save()));
    //输入干部职务
    connect(ui->add_but_CadrePost,SIGNAL(clicked(bool)),this,SLOT(add_CadrePost()));
    connect(ui->del_but_CadrePost,SIGNAL(clicked(bool)),this,SLOT(del_CadrePost()));
    //输入考核
    connect(ui->add_but_Check,SIGNAL(clicked(bool)),this,SLOT(add_Check()));
    connect(ui->del_but_Check,SIGNAL(clicked(bool)),this,SLOT(del_Check()));
    //奖惩
    connect(ui->add_but_rorp,SIGNAL(clicked(bool)),this,SLOT(add_rorp()));
    connect(ui->add_but_punish,SIGNAL(clicked(bool)),this,SLOT(add_punish()));
    connect(ui->del_but_reward,SIGNAL(clicked(bool)),this,SLOT(del_reward()));
    connect(ui->del_but_punish,SIGNAL(clicked(bool)),this,SLOT(del_punish()));
    //输入教育经历
    connect(ui->add_but_edu,SIGNAL(clicked(bool)),this,SLOT(add_Edu()));
    connect(ui->del_but_edu,SIGNAL(clicked(bool)),this,SLOT(del_Edu()));
    //输入工作经历
    connect(ui->add_but_Work,SIGNAL(clicked(bool)),this,SLOT(add_Work()));
    connect(ui->del_but_Work,SIGNAL(clicked(bool)),this,SLOT(del_Work()));
    //输入家庭成员
    connect(ui->add_but_family,SIGNAL(clicked(bool)),this,SLOT(add_family()));
    connect(ui->del_but_family,SIGNAL(clicked(bool)),this,SLOT(del_family()));
    //任免表导入
    //点击选取文件、弹出文件对话框
    //connect(ui->qualifyBookIn,SIGNAL(clicked()),this,SLOT(wordOperator()));
}
qualifyDocu::~qualifyDocu()
{
    delete ui;
    delete completer;
}
void qualifyDocu::setLock(){
    ui->borndate->setEnabled(false);
    ui->partydate->setEnabled(false);
    ui->workdate->setEnabled(false);
    ui->nationBox->setEnabled(false);
    ui->sexBox->setEnabled(false);
    ui->bornEdit->setEnabled(false);
    ui->nativeBox->setEnabled(false);
    ui->specialEdit->setEnabled(false);
    ui->unitBox->setEnabled(false);
    ui->skillEdit->setEnabled(false);
    ui->healthEdit->setEnabled(false);
    //民族
    QStringList strings;
    QSqlQuery query("SELECT Nation FROM NationCode ORDER BY NationID");
    while (query.next()) {
    QString nation = query.value(0).toString();
    strings.append(nation);
    }
    completer = new QCompleter(strings, this);
    ui->nationBox->clear();
    ui->nationBox->addItems(strings);
    ui->nationBox->setEditable(true);
    ui->nationBox->setCompleter(completer);
    //籍贯
    QStringList strings3;
    QSqlQuery query3("SELECT AdminArea FROM AdminAreaCode");
    while (query3.next()) {
    QString area = query3.value(0).toString();
    strings3.append(area);
    }
    completer = new QCompleter(strings3, this);
    ui->nativeBox->clear();
    ui->nativeBox->addItems(strings3);
    ui->nativeBox->setEditable(true);
    ui->nativeBox->setCompleter(completer);
    //单位
    QStringList strings2;
    QSqlQuery query2("SELECT unitname FROM unit ORDER BY unitid");
    while (query2.next()) {
    QString nation = query2.value(0).toString();
    strings2.append(nation);
    }
    completer = new QCompleter(strings2, this);
    ui->unitBox->clear();
    ui->unitBox->addItems(strings2);
    ui->unitBox->setEditable(true);
    ui->unitBox->setCompleter(completer);
}

void qualifyDocu::click_edit(){
    QString text=((QPushButton*)sender())->text();
        id_dialog=new IDDialog(this);
        id_dialog->setModal(true);

        connect(id_dialog,SIGNAL(sendData(QString,QString)),this,SLOT(updateData(QString,QString)));
        //connect(id_dialog,SIGNAL(reEdit()),this,SLOT());
        id_dialog->show();
}
void qualifyDocu::updateData(QString name, QString id){
    ui->nameEdit->setText(name);
    ui->IDNumEdit->setText(id);
    ui->bornEdit->setText("");
    //ui->nativeBox->setText("");
    ui->specialEdit->setText("");
    ui->skillEdit->setText("");
    ui->borndate->setEnabled(true);
    ui->partydate->setEnabled(true);
    ui->workdate->setEnabled(true);
    ui->nationBox->setEnabled(true);
    ui->sexBox->setEnabled(true);
    ui->bornEdit->setEnabled(true);
    ui->nativeBox->setEnabled(true);
    ui->specialEdit->setEnabled(true);
    ui->unitBox->setEnabled(true);
    ui->skillEdit->setEnabled(true);
    ui->healthEdit->setEnabled(true);
}

void qualifyDocu::click_save(){
    //setLock();
    QString ID=ui->IDNumEdit->text();
    QString name=ui->nameEdit->text();
    if(name.count()==0||ID.count()==0)
    {
        QMessageBox::information(this,"提示信息","请先输入姓名和身份证");
        return;
    }
    //性别
    QString sex=ui->sexBox->currentText();
    if(sex==QString::fromLocal8Bit("男")){
        sex="0";
    }
    if(sex==QString::fromLocal8Bit("女")){
        sex="1";
    }
    //民族代码
    QString nation=ui->nationBox->currentText();
    QString nationid;
    QSqlQuery query("SELECT NationID FROM NationCode where Nation='"+nation+"'");
    while (query.next()) {
    nationid = query.value(0).toString();
    }
    //籍贯
    QString nativePlace=ui->nativeBox->currentText();
    QString areaid;
    QSqlQuery queryyyy("SELECT AdminAreaID FROM AdminAreaCode where AdminArea='"+nativePlace+"'");
    while (queryyyy.next()) {
    areaid = queryyyy.value(0).toString();
    }
    //出生地
    QString bornPlace=ui->bornEdit->text();
    //出生日期
    QString borndate=ui->borndate->text();
    //qDebug()<<"出生"<<borndate;
    //borndate=borndate+"-01";
    //入党时间
    QString partydate=ui->partydate->text();
    //borndate=borndate+"-01";
    //参加工作时间
    QString workdate=ui->workdate->text();
    //专长
    QString special=ui->specialEdit->text();
    //所在单位
    QString unitname=ui->unitBox->currentText();
    QString unitid;
    QSqlQuery query4;
    query4.exec("SELECT unitid FROM ZZB.unit where unitname='"+unitname+"'");
    while (query4.next()) {
    unitid = query4.value(0).toString();
    }
    //健康状况
    QString health=ui->healthEdit->text();

   /* bool ok3=query4.exec("");
    if(!ok3){
        QMessageBox::information(this,"提示信息","职称保存失败!");
    }*/

    QSqlQuery query2;
    //INSERT INTO `CadreInfo`(`Sex`,`NationID`,`NativePlace`,`Birthplace`,`Birth`,`PartyTime`,`JoinWorkTime`,`Speciality`,CadreName,IDNum)VALUES('"+sex+"','"+nationid+"','"+nativePlace+"','"+bornPlace+"','"+borndate+"','"+partydate+"','"+workdate+"','"+special+"','"+ui->nameEdit->text()+"','"+ID+"')
    QString sql="update `CadreInfo` set Sex='"+sex+"',Speciality='"+special+"',Health='"+health+"',NationID='"+nationid+"',NativePlace='"+areaid+"',Birthplace='"+bornPlace+"',Birth='"+borndate+"',PartyTime='"+partydate+"',JoinWorkTime='"+workdate+"',UnitID='"+unitid+"' where IDNum='"+ID+"'";
    bool ok=query2.exec(sql);
    //qDebug()<<ok<<ID;


    //技术职务
    //先查找是否已存在该人的技术职务/职称
    QString titletype=ui->skillEdit->text();
    QSqlQuery qqqqq("select * from Title where IDNum='"+ID+"'");
    bool ok2;
    if(qqqqq.next())//不为空即已存在
    {
        QSqlQuery query3;
        QString sql2="update Title set TitleType='"+titletype+"' where IDNum='"+ID+"'";
        ok2=query3.exec(sql2);
    }
    else{
    QSqlQuery query3;
    QString sql2="INSERT INTO Title(TitleType,IDNum) VALUES('"+titletype+"','"+ID+"') ";
    ok2=query3.exec(sql2);
    }
    //qDebug()<<ok2;
    if(ok&&ok2){
        QMessageBox::information(this,"提示信息","成功保存!");
    }
    else{
            QMessageBox::information(this,"提示信息","成功失败，请检查输入信息是否符合标准!");
      }

    
}
void qualifyDocu::showPostInfo(){
    //sqlconnect(db);
    ui->postTable->setRowCount(0);
    QSqlQuery query;
    bool ok=query.exec("select PostName,QualifyType,UnitID from Post where IDNum='"+ui->IDNumEdit->text()+"'");
    //qDebug()<<ok;
    while(query.next())
    {
    int rowc=ui->postTable->rowCount();//获取行数
    ui->postTable->insertRow(rowc);
    QString a=query.value(0).toString();//职务
    ui->postTable->setItem(rowc,0,new QTableWidgetItem(a));
    //任免类型
    QString z=query.value(1).toString();
    if(z==QString::fromLocal8Bit("0"))
    ui->postTable->setItem(rowc,1,new QTableWidgetItem("现任"));
    if(z==QString::fromLocal8Bit("1"))
    ui->postTable->setItem(rowc,1,new QTableWidgetItem("拟任"));
    if(z==QString::fromLocal8Bit("2"))
    ui->postTable->setItem(rowc,1,new QTableWidgetItem("拟免"));
    //单位id
    //QString unit=query.value(2).toString();
    QString unit=query.value(2).toString();
    QString un;
    QSqlQuery quuu("SELECT unitname FROM ZZB.unit where unitid='"+unit+"'");
    while (quuu.next()) {
    un = quuu.value(0).toString();
    }
    ui->postTable->setItem(rowc,2,new QTableWidgetItem(un));
    }
    //db.close();
}
void qualifyDocu::del_CadrePost(){
    //qDebug()<<"成功调用";
    //QTableWidgetItem * item = ui->postTable->currentRow();
    //if(item==NULL)return;
    //item->column()
    //int row=item->row();
    //item->column();
    //QString str=QString::number(id,10);
    int row=ui->postTable->currentRow();
    //qDebug()<<row;
    if(row==-1){
        QMessageBox::information(this,"提示信息","未选中删除行！");
        return;
    }
    //QTableWidgetItem *post = new QTableWidgetItem;
    QString post = ui->postTable->item(row,0)->text();
    QString posttype = ui->postTable->item(row,1)->text();
    if(posttype==QString::fromLocal8Bit("现任"))
    posttype="0";
    if(posttype==QString::fromLocal8Bit("拟任"))
    posttype="1";
    if(posttype==QString::fromLocal8Bit("拟免"))
    posttype="2";
    //sqlconnect(db);
    QSqlQuery query;
    QString sql="DELETE FROM Post WHERE PostName='"+post+"' and QualifyType='"+posttype+"' and IDNum='"+ui->IDNumEdit->text()+"'";
    bool ok=query.exec(sql);
    if(ok)
    {
            qDebug()<<"删除成功！！";
            ui->postTable->removeRow(row);
            showPostInfo();

    }
    else
    {
            qDebug()<<"删除失败！！";
    }
    //this->db.close();

}

void qualifyDocu::add_CadrePost(){
    QString name=ui->nameEdit->text();
    QString ID=ui->IDNumEdit->text();
    //sqlconnect(db);
    if(name.count()==0||ID.count()==0)
    {
        QMessageBox::information(this,"提示信息","请先输入姓名和身份证");
        return;
    }
    post_dialog=new cadrepostDialog(this);
    connect(this,SIGNAL(sendID(QString)),post_dialog,SLOT(reciveID(QString)));
    emit sendID(ID);
    post_dialog->setModal(true);
    post_dialog->show();
}
void qualifyDocu::showCheckInfo(){
    //sqlconnect(db);
    ui->checkTable->setRowCount(0);
    QSqlQuery query;
    bool ok=query.exec("select CheckYear,CheckResult from `Check` where IDNum='"+ui->IDNumEdit->text()+"'");
    //qDebug()<<ok<<"调用";
    while(query.next())
    {
    int rowc=ui->checkTable->rowCount();//获取行数
    ui->checkTable->insertRow(rowc);
    QString a=query.value(0).toString();//年度
    //qDebug()<<a;
    ui->checkTable->setItem(rowc,0,new QTableWidgetItem(a));
    //考核结果
    QString m=query.value(1).toString();
    //qDebug()<<m;
    ui->checkTable->setItem(rowc,1,new QTableWidgetItem(m));
    }
    //db.close();
}

void qualifyDocu::add_Check(){
    QString name=ui->nameEdit->text();
    QString ID=ui->IDNumEdit->text();
    //sqlconnect(db);
    if(name.count()==0||ID.count()==0)
    {
        QMessageBox::information(this,"提示信息","请先输入姓名和身份证");
        return;
    }
    check_dia=new check_dialog(this);
    connect(this,SIGNAL(sendID(QString)),check_dia,SLOT(reciveID(QString)));
    emit sendID(ID);
    check_dia->setModal(true);
    check_dia->show();

}
void qualifyDocu::del_Check(){
    int row=ui->checkTable->currentRow();
    if(row==-1){
        QMessageBox::information(this,"提示信息","未选中删除行！");
        return;
    }
    //获取meetingid
    QTableWidgetItem *check = new QTableWidgetItem;
    check = ui->checkTable->item(row,0);
    QString str=check->text();
    //qDebug()<<str;
    if(str=="")
        return;
    //int postID=str.toInt();
    //sqlconnect(db);
    QSqlQuery query;
    QString sql="DELETE FROM `Check` WHERE CheckYear="+str;
    bool ok=query.exec(sql);
    if(ok)
    {
            qDebug()<<"删除成功！！";
            ui->checkTable->removeRow(row);
            showCheckInfo();

    }
    else
    {
            qDebug()<<"删除失败！！";
    }
    //this->db.close();
}

//奖惩
void qualifyDocu::showRewardInfo(){
    //sqlconnect(db);
    ui->rewardTable->setRowCount(0);
    QSqlQuery query;
    bool ok=query.exec("select RewardTime,RewardName from `Reward` where `Reward`.IDNum='"+ui->IDNumEdit->text()+"'");
    //qDebug()<<ok<<"调用";
    while(query.next())
    {
    int rowc=ui->rewardTable->rowCount();//获取行数
    ui->rewardTable->insertRow(rowc);
    QString a=query.value(0).toString();//时间
    //qDebug()<<a;
    ui->rewardTable->setItem(rowc,0,new QTableWidgetItem(a));
    //名称
    QString m=query.value(1).toString();
    //qDebug()<<m;
    ui->rewardTable->setItem(rowc,1,new QTableWidgetItem(m));
    }

    //db.close();
}
void qualifyDocu::showPunishInfo(){
    ui->punishTable->setRowCount(0);
    QSqlQuery query;
    //,PunishTime,PunishName,Punish
    bool ok2=query.exec("select PunishTime,PunishName from Punish where Punish.IDNum='"+ui->IDNumEdit->text()+"'");
    //qDebug()<<ok<<"调用";
    while(query.next())
    {
    int rowc=ui->punishTable->rowCount();//获取行数
    ui->punishTable->insertRow(rowc);
    QString a=query.value(0).toString();//时间
    //qDebug()<<a;
    ui->punishTable->setItem(rowc,0,new QTableWidgetItem(a));
    //名称
    QString m=query.value(1).toString();
    //qDebug()<<m;
    ui->punishTable->setItem(rowc,1,new QTableWidgetItem(m));
    }
}

void qualifyDocu::add_rorp(){
    QString name=ui->nameEdit->text();
    QString ID=ui->IDNumEdit->text();
    //sqlconnect(db);
    if(name.count()==0||ID.count()==0)
    {
        QMessageBox::information(this,"提示信息","请先输入姓名和身份证");
        return;
    }
    reorpuDia=new rewardorpunish(this);
    connect(this,SIGNAL(sendID(QString)),reorpuDia,SLOT(reciveID(QString)));
    emit sendID(ID);
    reorpuDia->setModal(true);
    reorpuDia->show();
}
void qualifyDocu::add_punish(){
    QString name=ui->nameEdit->text();
    QString ID=ui->IDNumEdit->text();
    //sqlconnect(db);
    if(name.count()==0||ID.count()==0)
    {
        QMessageBox::information(this,"提示信息","请先输入姓名和身份证");
        return;
    }
    punishDia=new punishDialog(this);
    connect(this,SIGNAL(sendID(QString)),punishDia,SLOT(reciveID(QString)));
    emit sendID(ID);
    punishDia->setModal(true);
    punishDia->show();
}

void qualifyDocu::del_reward(){
    int row=ui->rewardTable->currentRow();
    if(row==-1){
        QMessageBox::information(this,"提示信息","未选中删除行！");
        return;
    }
    QString rdate=ui->rewardTable->item(row,0)->text();
    QString rname=ui->rewardTable->item(row,1)->text();
    QSqlQuery query;
    QString sql="DELETE FROM `Reward` WHERE RewardTime='"+rdate+"' and RewardName='"+rname+"' and IDNum='"+ui->IDNumEdit->text()+"'";
    bool ok=query.exec(sql);
    if(ok)
    {
            qDebug()<<"删除成功！！";
            ui->rewardTable->removeRow(row);
            showRewardInfo();

    }
    else
    {
            qDebug()<<"删除失败！！";
    }
}

void qualifyDocu::del_punish(){
    int row=ui->punishTable->currentRow();
    if(row==-1){
        QMessageBox::information(this,"提示信息","未选中删除行！");
        return;
    }
    QString pdate=ui->punishTable->item(row,0)->text();
    QString pname=ui->punishTable->item(row,1)->text();
    QSqlQuery query;
    QString sql="DELETE FROM `Punish` WHERE PunishTime='"+pdate+"' and PunishName='"+pname+"' and IDNum='"+ui->IDNumEdit->text()+"'";
    bool ok=query.exec(sql);
    if(ok)
    {
            qDebug()<<"删除成功！！";
            ui->punishTable->removeRow(row);
            showPunishInfo();

    }
    else
    {
            qDebug()<<"删除失败！！";
    }
}


void qualifyDocu::showEduInfo(){
    //sqlconnect(db);
    ui->eduTable->setRowCount(0);
    QSqlQuery query;
    bool ok=query.exec("select * from `Edu` where IDNum='"+ui->IDNumEdit->text()+"'");
    //qDebug()<<ok<<"调用";
    while(query.next())
    {
    int rowc=ui->eduTable->rowCount();//获取行数
    ui->eduTable->insertRow(rowc);
    //开始时间
    QString a2=query.value(1).toString();
    //qDebug()<<a2;
    ui->eduTable->setItem(rowc,0,new QTableWidgetItem(a2));

    QString a3=query.value(2).toString();
    //qDebug()<<a3;
    ui->eduTable->setItem(rowc,1,new QTableWidgetItem(a3));
    //学历状态
    QString a4=query.value(3).toString();//id
    //qDebug()<<a4;
    if(a4=="1")
        a4="毕业";
    if(a4=="2")
        a4="结业";
    if(a4=="3")
        a4="未结业";
    if(a4=="4")
        a4="肄业";
    if(a4=="9")
        a4="其他";
    ui->eduTable->setItem(rowc,2,new QTableWidgetItem(a4));
    //学历
    QString a5=query.value(4).toString();
    //qDebug()<<a5;
    QSqlQuery q1("select Education from EducationCode where EducationID='"+a5+"'" );
    while (q1.next()) {
        a5=q1.value(0).toString();
    }
    ui->eduTable->setItem(rowc,3,new QTableWidgetItem(a5));
    //学位
    QString a6=query.value(5).toString();
    //qDebug()<<a6;
    QSqlQuery q2("select Degree from DegreeCode where DegreeID='"+a6+"'" );
    while (q2.next()) {
        a6=q2.value(0).toString();
    }
    ui->eduTable->setItem(rowc,4,new QTableWidgetItem(a6));

    QString a7=query.value(6).toString();
    //qDebug()<<a7;
    ui->eduTable->setItem(rowc,5,new QTableWidgetItem(a7));

    QString a8=query.value(7).toString();
    //qDebug()<<a8;
    ui->eduTable->setItem(rowc,6,new QTableWidgetItem(a8));
    //在职/全日
    QString a9=query.value(8).toString();
    //qDebug()<<a9;
    if(a9=="0")
        ui->eduTable->setItem(rowc,7,new QTableWidgetItem("在职"));
    if(a9=="1")
        ui->eduTable->setItem(rowc,7,new QTableWidgetItem("全日制"));
    }
    //db.close();
}
void qualifyDocu::add_Edu(){
    QString name=ui->nameEdit->text();
    QString ID=ui->IDNumEdit->text();
    //sqlconnect(db);
    if(name.count()==0||ID.count()==0)
    {
        QMessageBox::information(this,"提示信息","请先输入姓名和身份证");
        return;
    }
    edu_dia=new eduDialog(this);
    connect(this,SIGNAL(sendID(QString)),edu_dia,SLOT(reciveID(QString)));
    emit sendID(ID);
    edu_dia->setModal(true);
    edu_dia->show();
}


void qualifyDocu::del_Edu(){
    int row=ui->eduTable->currentRow();
    if(row==-1){
        QMessageBox::information(this,"提示信息","未选中删除行！");
        return;
    }
    QTableWidgetItem *edu = new QTableWidgetItem;
    edu = ui->eduTable->item(row,0);
    QString str=edu->text();//入学时间
    QString school=ui->eduTable->item(row,5)->text();//学校
    QString major=ui->eduTable->item(row,6)->text();//专业
    //qDebug()<<str;
    if(str=="")
        return;
    //int postID=str.toInt();
    //sqlconnect(db);
    QSqlQuery query;
    QString sql="DELETE FROM `Edu` WHERE `StartTime`='"+str+"'and School='"+school+"' and `Major`='"+major+"' and IDNum='"+ui->IDNumEdit->text()+"'";
    bool ok=query.exec(sql);
    if(ok)
    {
            qDebug()<<"删除成功！！";
            ui->eduTable->removeRow(row);
            showEduInfo();

    }
    else
    {
            qDebug()<<"删除失败！！";
    }
    //this->db.close();
}
void qualifyDocu::showWorkInfo(){
    //sqlconnect(db);
    ui->workTable->setRowCount(0);
    QSqlQuery query;
    bool ok=query.exec("select StartTime,EndTime,UnitName,PostName from `Experience` where IDNum='"+ui->IDNumEdit->text()+"'");
    //qDebug()<<ok<<"调用";
    while(query.next())
    {
    int rowc=ui->workTable->rowCount();//获取行数
    ui->workTable->insertRow(rowc);
    QString a=query.value(0).toString();//开始时间
    //qDebug()<<a;
    ui->workTable->setItem(rowc,0,new QTableWidgetItem(a));
    //结束时间
    QString a2=query.value(1).toString();
    //qDebug()<<a2;
    ui->workTable->setItem(rowc,1,new QTableWidgetItem(a2));
    //单位
    QString a3=query.value(2).toString();
    //qDebug()<<a3;
    ui->workTable->setItem(rowc,2,new QTableWidgetItem(a3));
    //职务
    QString a4=query.value(3).toString();
    //qDebug()<<a4;
    ui->workTable->setItem(rowc,3,new QTableWidgetItem(a4));
    }
    //db.close();
}
void qualifyDocu::add_Work(){
    QString name=ui->nameEdit->text();
    QString ID=ui->IDNumEdit->text();
    if(name.count()==0||ID.count()==0)
    {
        QMessageBox::information(this,"提示信息","请先输入姓名和身份证");
        return;
    }
    work_dia=new workDialog(this);
    connect(this,SIGNAL(sendID(QString)),work_dia,SLOT(reciveID(QString)));
    emit sendID(ID);
    work_dia->setModal(true);
    work_dia->show();
}


void qualifyDocu::del_Work(){
    int row=ui->workTable->currentRow();
    QString ID=ui->IDNumEdit->text();
    if(row==-1){
        QMessageBox::information(this,"提示信息","未选中删除行！");
        return;
    }
    QTableWidgetItem *work = new QTableWidgetItem;
    work = ui->workTable->item(row,0);
    QString str=work->text();
    //qDebug()<<str;
    if(str=="")
        return;
    //int postID=str.toInt();
    //sqlconnect(db);
    QSqlQuery query;
    QString sql="DELETE FROM `Experience` WHERE StartTime='"+str+"' and IDNum= '"+ID+"'";
    bool ok=query.exec(sql);
    if(ok)
    {
            qDebug()<<"删除成功！！";
            ui->workTable->removeRow(row);
            showWorkInfo();

    }
    else
    {
            qDebug()<<"删除失败！！";
    }
    //this->db.close();
}

void qualifyDocu::showFamilyInfo(){
    //sqlconnect(db);
    ui->familyTable->setRowCount(0);
    QSqlQuery query;
    bool ok=query.exec("select * from `Family` where IDNum='"+ui->IDNumEdit->text()+"'");
    //qDebug()<<ok<<"调用";
    while(query.next())
    {
    int rowc=ui->familyTable->rowCount();//获取行数
    ui->familyTable->insertRow(rowc);

    QString a=query.value(1).toString();//姓名
    //qDebug()<<a;
    ui->familyTable->setItem(rowc,0,new QTableWidgetItem(a));
    //出生
    QString a2=query.value(2).toString();
    //qDebug()<<a2;
    ui->familyTable->setItem(rowc,1,new QTableWidgetItem(a2));
    //关系
    QString a3=query.value(3).toString();
    //qDebug()<<a3;
    QSqlQuery query2;
    query2.exec("select Relation from RelationCode where RelationID='"+a3+"'");
    while(query2.next()){
        a3=query2.value(0).toString();
    }
    ui->familyTable->setItem(rowc,2,new QTableWidgetItem(a3));
    //政治面貌
    QString a4=query.value(4).toString();
    //qDebug()<<a4;
    query2.exec("select Politic from PoliticCode where PoliticID='"+a4+"'");
    while(query2.next()){
        a4=query2.value(0).toString();
    }
    ui->familyTable->setItem(rowc,3,new QTableWidgetItem(a4));
    //单位
    QString a5=query.value(5).toString();
    //qDebug()<<a5;
    ui->familyTable->setItem(rowc,4,new QTableWidgetItem(a5));
    //职业
    QString a6=query.value(6).toString();
    //qDebug()<<a6;
    ui->familyTable->setItem(rowc,5,new QTableWidgetItem(a6));
    //身份证
    QString a7=query.value(8).toString();
    //qDebug()<<a7;
    ui->familyTable->setItem(rowc,6,new QTableWidgetItem(a7));

    }
    //db.close();
}
void qualifyDocu::add_family(){
    QString name=ui->nameEdit->text();
    QString ID=ui->IDNumEdit->text();
    if(name.count()==0||ID.count()==0)
    {
        QMessageBox::information(this,"提示信息","请先输入姓名和身份证");
        return;
    }
    fam_dia=new familyDialog(this);
    connect(this,SIGNAL(sendID(QString)),fam_dia,SLOT(reciveID(QString)));
    emit sendID(ID);
    fam_dia->setModal(true);
    fam_dia->show();
}


void qualifyDocu::del_family(){
    int row=ui->familyTable->currentRow();
    if(row==-1){
        QMessageBox::information(this,"提示信息","未选中删除行！");
        return;
    }
    QString name = ui->familyTable->item(row,0)->text();
    QString relation=ui->familyTable->item(row,2)->text();
    QString relationid;
    QString NumID=ui->IDNumEdit->text();
    //sqlconnect(db);
    QSqlQuery query;
    query.exec("SELECT RelationID FROM RelationCode where Relation='"+relation+"'");
    while (query.next()) {
    relationid = query.value(0).toString();
    }
    //QSqlQuery query;
    QString sql="DELETE FROM `Family` WHERE Name='"+name+"' and Relation='"+relationid+"' and IDNum='"+NumID+"'" ;
    bool ok=query.exec(sql);
    if(ok)
    {
            qDebug()<<"删除成功！！";
            ui->familyTable->removeRow(row);
            showFamilyInfo();

    }
    else
    {
            qDebug()<<"删除失败！！";
    }
    //this->db.close();
}












/*
添加行删除行槽函数实现

//干部职务
void qualifyDocu::on_but_Add_CadrePost()
{
//    QAbstractItemModel *model = ui->tableWidget->model();
//     model->insertRow(model->rowCount());
    int cols=ui->postTable->columnCount();
    int rows=ui->postTable->rowCount();
    //qDebug()<<rows;
    ui->postTable->insertRow(rows);
    for(int i=0;i<cols;i++)
    {
        ui->postTable->setItem(rows,i,new QTableWidgetItem("new"+QString::number(rows)));
    }
    ui->postTable->selectRow(rows);
}
void qualifyDocu::on_but_Del_CadrePost(){
    QTableWidgetItem * item = ui->postTable->currentItem();
    if(item==NULL)return;
    ui->postTable->removeRow(item->row());
}
//简历
void qualifyDocu::on_but_Add_Vita(){
    int cols=ui->vitaTable->columnCount();
    int rows=ui->vitaTable->rowCount();
    //qDebug()<<rows;
    ui->vitaTable->insertRow(rows);
    for(int i=0;i<cols;i++)
    {
        ui->vitaTable->setItem(rows,i,new QTableWidgetItem("new"+QString::number(rows)));
    }
    ui->vitaTable->selectRow(rows);
}
void qualifyDocu::on_but_Del_Vita(){

    QTableWidgetItem * item = ui->vitaTable->currentItem();
    if(item==NULL)return;
    ui->vitaTable->removeRow(item->row());
}
//考核表
void qualifyDocu::on_but_Add_Check(){
    int cols=ui->checkTable->columnCount();
    int rows=ui->checkTable->rowCount();
    //qDebug()<<rows;
    ui->checkTable->insertRow(rows);
    for(int i=0;i<cols;i++)
    {
        ui->checkTable->setItem(rows,i,new QTableWidgetItem("new"+QString::number(rows)));
    }
    ui->checkTable->selectRow(rows);
}
void qualifyDocu::on_but_Del_Check(){

    QTableWidgetItem * item = ui->checkTable->currentItem();
    if(item==NULL)return;
    ui->checkTable->removeRow(item->row());
}
//对任免表word文档的读取并分析字段
void qualifyDocu::wordOperator(){
    QString path=QFileDialog::getOpenFileName(this,"打开文件","/home/wql/Documents");
    //ui->lineEdit->setText(path);
    //先判断文件格式gbk、utf-8、、，再根据格式读取
    QFile file(path);//参数为文件路径
    file.open(QIODevice::ReadOnly);
    //QByteArray array=file.readAll();
    QTextCodec *codec = QTextCodec::codecForName("gbk");
    QString strAll=codec->toUnicode(file.readAll());
    ui->textBrowser->setText(strAll);
}
*/

void qualifyDocu::on_saveButton_clicked()
{

}
